package game.square.temperature;

import static org.junit.Assert.*;

import org.junit.*;

public class TemperatureTest {
	
	
	private static Temperature temperature50Cel;
	/**
	 * Set up a mutable test fixture.
	 * 
	 * @post   The variable temperature50Cel references a new
	 *         temperature with a temperature value of 50 celcius,
	 *         a minimum temperature of -200 degrees celcius and
	 *         a maximum temperature of 5000 degrees celcius.
	 */
	@Before
	public void setUp() throws Exception {
		temperature50Cel = new Temperature(50,-200, 5000, TemperatureScale.CELCIUS);	
	}

	@Test
	public final void toTemperatureScale_SingleCase(){
		assertEquals(50, Temperature.toTemperatureScale(50,TemperatureScale.CELCIUS,TemperatureScale.CELCIUS));
		assertEquals(323, Temperature.toTemperatureScale(50,TemperatureScale.CELCIUS,TemperatureScale.KELVIN));
		assertEquals(122, Temperature.toTemperatureScale(50,TemperatureScale.CELCIUS,TemperatureScale.FAHRENHEIT));
		assertEquals(-223, Temperature.toTemperatureScale(50,TemperatureScale.KELVIN,TemperatureScale.CELCIUS));
		assertEquals(50, Temperature.toTemperatureScale(50,TemperatureScale.KELVIN,TemperatureScale.KELVIN));
		assertEquals(-370, Temperature.toTemperatureScale(50,TemperatureScale.KELVIN,TemperatureScale.FAHRENHEIT));
		assertEquals(10, Temperature.toTemperatureScale(50,TemperatureScale.FAHRENHEIT,TemperatureScale.CELCIUS));
		assertEquals(283, Temperature.toTemperatureScale(50,TemperatureScale.FAHRENHEIT,TemperatureScale.KELVIN));
		assertEquals(50, Temperature.toTemperatureScale(50,TemperatureScale.FAHRENHEIT,TemperatureScale.FAHRENHEIT));
	}
	
	@Test
	public final void setTemperature_LegalCase() {
		temperature50Cel.setTemperatureValue(100, TemperatureScale.CELCIUS);
		assertEquals(100,temperature50Cel.getTemperatureValue(TemperatureScale.CELCIUS));
		temperature50Cel.setTemperatureValue(100,TemperatureScale.KELVIN);
		assertEquals(100,temperature50Cel.getTemperatureValue(TemperatureScale.KELVIN));
		temperature50Cel.setTemperatureValue(100,TemperatureScale.FAHRENHEIT);
		assertEquals(100,temperature50Cel.getTemperatureValue(TemperatureScale.FAHRENHEIT));
	}
	
	@Test(expected = IllegalArgumentException.class)
	public final void setTemperature_LowerIllegalCaseCelcius() throws IllegalArgumentException {
		temperature50Cel.setTemperatureValue(-201, TemperatureScale.CELCIUS);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public final void setTemperature_LowerIllegalCaseKelvin() throws IllegalArgumentException {
		temperature50Cel.setTemperatureValue(72,TemperatureScale.KELVIN);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public final void setTemperature_LowerIllegalCaseFahrenheit() throws IllegalArgumentException {
		temperature50Cel.setTemperatureValue(-330,TemperatureScale.FAHRENHEIT);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public final void setTemperature_UpperIllegalCaseCelcius() throws IllegalArgumentException {
		temperature50Cel.setTemperatureValue(5001,TemperatureScale.CELCIUS);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public final void setTemperature_UpperIllegalCaseKelvin() throws IllegalArgumentException {
		temperature50Cel.setTemperatureValue(5274,TemperatureScale.KELVIN);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public final void setTemperature_UpperIllegalCaseFahrenheit() throws IllegalArgumentException {
		temperature50Cel.setTemperatureValue(9034,TemperatureScale.FAHRENHEIT);
	}
	
	@Test
	public final void add_LegalCase(){
		Temperature newTemp = temperature50Cel.add(new Temperature(-15, -100, 4000, TemperatureScale.CELCIUS));
		assertEquals(35, newTemp.getTemperatureValue(TemperatureScale.CELCIUS));
		assertEquals(-100, newTemp.getMinTemperature(TemperatureScale.CELCIUS));
		assertEquals(4000, newTemp.getMaxTemperature(TemperatureScale.CELCIUS));
	}
	
	
}
